<style >
  table.formTable {
    font-family: verdana, arial, sans-serif;
    font-size: 0.875rem;
    color: #333333;
    border-width: 0px;
    border-color: #dcdfe6;
    border-collapse: collapse;
    width: 100%;
  }

  table.formTable td {
    border-width: 0px;
    padding: 20px;
    border-style: solid;
    border-color: #dcdfe6;
    background-color: #ffffff;
    padding:2px;
    text-align: center;
  }

  table.formTable td:first-child {
    width: 100px;
    text-align: right;
  }

  table.formTable td:last-child {
  	 color: #E6A23C; 
  }
  
      #tableIconForBizStyleLine + .layui-table-view .layui-table-body tbody > tr > td {
        padding: 0;
    }

    #tableIconForBizStyleLine + .layui-table-view .layui-table-body tbody > tr > td > .layui-table-cell {
        height: 60px;
        line-height: 60px;
    }

    .tdImg {
        width: 35px;
        height:35px;
        max-width: none;
        cursor: pointer;
    }

    .layui-table-view {
        margin: 0;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar" id="tbToolBar">
                <div class="layui-form-item">
					<div class="layui-inline">
						<button id="btnAddBizStyleLine" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>新增</button>
					</div>
                    <div class="layui-inline" style="float: right;margin-right: 0px;">
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<label class="layui-form-label w-auto">名称</label>
							<div class="layui-input-inline mr0">
								<input name="name" class="layui-input" type="text" placeholder="请输入名称"/>
							</div>
						</div>
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<button class="layui-btn icon-btn" lay-filter="formSubSearchBizStyleLine" lay-submit>
								<i class="layui-icon">&#xe615;</i>查询
							</button>
						</div>					
					</div>
				</div>
				<table class="layui-table" id="tableBizStyleLine" lay-filter="tableBizStyleLine"></table>
			</div>
		</div>
	</div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBarBizStyleLine">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="copy">复制</a>
</script>
<!-- 表格状态列 -->
<script type="text/html" id="tableStateBizStyleLine">
#[[  {{#  if(d.status === '1'){ }}
    <span style="color: #23aa2e;">正常</span>
  {{#  } else { }}
	<span style="color: #ff0000;">禁止</span>
  {{#  } }}
]]#
</script>


<!-- 表单弹窗-->
<script type="text/html" id="modelBizStyleLine"> 
    <form id="modelBizStyleLineForm" lay-filter="modelBizStyleLineForm" class="layui-form model-form" style="padding: 5px;">
        <input name="id" type="hidden"  />
		<table class="formTable">
			<tr>
				<td>名称</td>
				<td colspan="3" style="text-align: left;">
                	<input name="name"  placeholder="请输入名称" type="text" class="layui-input" lay-verType="tips" lay-verify="required" required/>
                </td>
			</tr>
			<tr>
				<td>标识</td>
				<td colspan="3" style="text-align: left;">
                	<input name="code"  placeholder="请输入标识" type="text" class="layui-input" />
                </td>
			</tr>			
			<tr>
				<td>材质类型</td>
				<td colspan="3" style="text-align: left;">
			      <select name="materialType" lay-filter="materialType"  lay-verify="required" required>
			        <option value="solid" >实线</option>
			        <option value="dash"  >虚线</option>
			        <option value="outline"  >轮廓线</option>
			        <option value="glow"  >光晕线</option>
			        <option value="arrow"  >箭头</option>
			        <option value="flow1">流动线一</option>
					<option value="flow2">流动线二</option>
					<option value="flow3">流动线三</option>
			      </select>
                </td>
			</tr>
			<tr>
				<td>颜色</td>
				<td colspan="3" style="text-align: left;">
					<input type="hidden" name="color"  id="color-input">
					<div id="color"></div>			      
                </td>
			</tr>				
			<tr>
				<td>宽度</td>
				<td colspan="3">
                	<input name="width"  placeholder="请输入宽度" value="3" type="text" class="layui-input" lay-verType="tips" lay-verify="required" required/>
                </td>              
			</tr>
			<tr>
				<td>贴地</td>
				<td colspan="3" style="text-align: left;">
			      <select name="clampToGround" lay-filter="clampToGround"  lay-verify="required" required>
			        <option value="0"  >否</option>
			        <option value="1" >是</option>
			      </select>
                </td>
			</tr>
			<tr>
				<td>闭合</td>
				<td colspan="3" style="text-align: left;">
			      <select name="loop" lay-filter="loop"  lay-verify="required" required>
			        <option value="0"  >否</option>
			        <option value="1" >是</option>
			      </select>
                </td>
			</tr>			

			<tr id="outlineColor-tr" style="display: none;">
				<td>边线颜色</td>
				<td colspan="3" style="text-align: left;">
					<input type="hidden" name="outlineColor"  id="outlineColor-input">
					<div id="outlineColor"></div>			      
                </td>
			</tr>
			<tr id="outlineWidth-tr" style="display: none;">
				<td>边线宽度</td>
				<td colspan="3" style="text-align: left;">
                	<input name="outlineWidth" placeholder="请输入宽度" type="text" class="layui-input" lay-verType="tips" />
                </td>
			</tr>
			
			<tr id="gapColor-tr" style="display: none;">
				<td>间隔颜色</td>
				<td colspan="3" style="text-align: left;">
					<input type="hidden" name="gapColor" id="gapColor-input">
					<div id="gapColor"></div>		
				</td>
			</tr>			

			<tr id="dashLength-tr" style="display: none;">
				<td>间隔距离</td>
				<td colspan="3" style="text-align: left;">
                	<input name="dashLength" placeholder="请输入(默认16)" type="text" class="layui-input" lay-verType="tips" />
                </td>
			</tr>
			<tr id="dashPattern-tr" style="display: none;">
				<td>dashPattern</td>
				<td colspan="3" style="text-align: left;">
                	<input name="dashPattern" placeholder="请输入(默认255)" type="text" class="layui-input" lay-verType="tips" />
                </td>
			</tr>

			<tr id="glowPower-tr" style="display: none;">
				<td>发光强度</td>
				<td colspan="3" style="text-align: left;">
                	<input name="glowPower"  placeholder="请输入(0~1)" type="text"   class="layui-input" lay-verType="tips" />
                </td>
			</tr>	
			<tr id="interval-tr" style="display: none;">
				<td>时间间隔</td>
				<td colspan="3" style="text-align: left;">
                	<input name="interval"  placeholder="请输入间隔距离" value="3" type="text" class="layui-input" lay-verType="tips" />
                </td>
			</tr>
																				
			<tr>
				<td>可视范围</td>
				<td >
                	<input name="distanceDisplayConditionX"  placeholder="请输入x" value="0" type="number" class="layui-input" lay-verType="tips"  />
                </td>
				<td >
                	<input name="distanceDisplayConditionY" placeholder="请输入y" value="50000" type="number" class="layui-input" lay-verType="tips" />
                </td>                
			</tr>						
			<tr>
				<td>是否可用</td>
				<td colspan="3" style="text-align: left;">
			      <select name="status" lay-filter="status"  lay-verify="required" required>
					<option value="1" >启用</option>
			        <option value="0" >禁用</option>
			        <option value="1" >启用</option>
			      </select>
                </td>
			</tr>
			<tr>
				<td>序号</td>
				<td colspan="3">
                <input name="sort" placeholder="请输入序号" type="number" value="0"   class="layui-input"  
                       lay-verType="tips" lay-verify="required|number" required/>
                </td>
			</tr>
			<tr>
				<td colspan="4">
		            <button class="layui-btn" lay-filter="modelSubmitBizStyleLineForm" lay-submit>保存</button>
                </td>
			</tr>												
		</table>    
    </form>
</script>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin', 'config','colorpicker'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var config = layui.config;
        var colorpicker = layui.colorpicker;
        // 渲染表格
        var insTb = table.render({
            elem: '#tableBizStyleLine',
            url: '#(ctx)/biz/style/line/listData', 
            page: true,
            toolbar: false,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号'},
				/* {field: 'coverImg', sort: false, title: '缩略图'}, */
                {field: 'name', sort: false, title: '名称'},
                {
                    field: 'createTime', sort: false, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '创建时间'
                },
				{field: 'status', sort: false, templet: '#tableStateBizStyleLine', title: '状态', align: 'center'},
                {align: 'left', toolbar: '#tableBarBizStyleLine', title: '操作'}
            ]],
        });

        // 添加
		$('#btnAddBizStyleLine').click(function () {
			 showEditModel();
		});

        // 搜索
        form.on('submit(formSubSearchBizStyleLine)', function (data) {
            insTb.reload({where: data.field}, 'data');
        });

        // 工具条点击事件
        table.on('tool(tableBizStyleLine)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { 
            	showEditModel(data);
            } else if (layEvent === 'del') { 
                doDel(data.id, data.name);
            }
            else if (layEvent === 'copy') { 
            	copy(data.id, data.name);
            }
        });

        // 删除
        function doDel(id, name) {
            layer.confirm('确定要删除“【<span style="color:red;">' + name + '</span>】”吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('biz/style/line/delete', {
                    id: id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.message, {icon: 1});
                        insTb.reload({}, 'data');
                    } else {
                        layer.msg(res.message, {icon: 2});
                    }
                }, 'get');
            });
        }

        function copy(id, name) {
            layer.confirm('确定要克隆“【<span style="color:red;">' + name + '</span>】”吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('biz/style/line/copy', {
                    id: id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.message, {icon: 1});
                        insTb.reload({}, 'data');
                    } else {
                        layer.msg(res.message, {icon: 2});
                    }
                }, 'get');
            });
        }
        // 显示表单弹窗
        function showEditModel(data) {
            layer.open({
                type: 1,
                shade: 0.3,
                offset: 't'	,
                title: (data ? '修改' : '添加') + '',
                area:'500px',
                resize :false,
                content: $('#modelBizStyleLine').html(),
                success: function (layero, dIndex) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    form.val('modelBizStyleLineForm', data);  // 回显数据

                	colorpicker.render({//间隔颜色
                		elem: '#color',
                		color: (data&&data.color)?data.color:null,
                		format: 'rgb',
                		predefine: true,
                		alpha: true,
                		done: function(color) {
                			$('#color-input').val(color); //向隐藏域赋值
                			color || this.change(color); //清空时执行 change
                		},
                		change: function(color) {}
                	});
                	
                	colorpicker.render({//间隔颜色
                		elem: '#outlineColor',
                		color: (data&&data.outlineColor)?data.outlineColor:null,
                		format: 'rgb',
                		predefine: true,
                		alpha: true,
                		done: function(color) {
                			$('#outlineColor-input').val(color); //向隐藏域赋值
                			color || this.change(color); //清空时执行 change
                		},
                		change: function(color) {}
                	});	
                	
                	colorpicker.render({//间隔颜色
                		elem: '#gapColor',
                		color: (data&&data.gapColor)?data.gapColor:null,
                		format: 'rgb',
                		predefine: true,
                		alpha: true,
                		done: function(color) {
                			$('#gapColor-input').val(color); //向隐藏域赋值
                			color || this.change(color); //清空时执行 change
                		},
                		change: function(color) {}
                	});	
                	
                	form.on('select(materialType)', function(data){
                		if("outline"==data.value){
                			showForOutline();
                		}
                		else if("dash"==data.value){
                			showForDash();
                		} 
                		else if("glow"==data.value){
                			showForGlow();
                		} 
                		else if((data.value=='flow1' || data.value=='flow2' || data.value=='flow3')){
                			showForOd();
                		} 
                		else{
                			hiddenTr();
                		}
                		form.render();
                	})
                	
                	if(data&& data.materialType=='dash')
                		showForDash();
                	else if(data&& data.materialType=='outline')	
                		showForOutline();
                	else if(data&& data.materialType=='glow')
                		showForGlow();
                	else if(data&& (data.materialType=='flow1' || data.materialType=='flow2' || data.materialType=='flow3'))
                		showForOd();
                	else		
                		hiddenTr();
                    
                	
    			    form.on('submit(modelSubmitBizStyleLineForm)', function (data) {
    			        layer.load(2);
    			        var formData={}; 
    			        for(var key in data.field){
    			        	formData['bizStyleLine.'+key]=data.field[key];
    			        }
                        admin.req("biz/style/line/save",formData, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.close(dIndex);
                                layer.msg(res.message, {icon: 1});
                                insTb.reload({}, 'data');
                            } else {
                                layer.msg(res.message, {icon: 2});
                            }
                        }, 'get');
    			        return false;
    			    });
    			    form.render(); 
                },
                end:function(){
                }
            });
        }

    });
    
    
	//外边框材质
	function showForOutline(){
		$('#outlineColor-tr').css('display','');
		$('#outlineWidth-tr').css('display','');
		$('#glowPower-tr').css('display','none');
		$('#gapColor-tr').css('display','none');
		$('#dashLength-tr').css('display','none');
		$('#dashPattern-tr').css('display','none');
		$('#interval-tr').css('display','none');
		
	}
	//虚线材质
	function showForDash(){
		$('#gapColor-tr').css('display','');
		$('#dashLength-tr').css('display','');
		$('#dashPattern-tr').css('display','');
		$('#outlineColor-tr').css('display','none');
		$('#outlineWidth-tr').css('display','none');
		$('#glowPower-tr').css('display','none');
		$('#interval-tr').css('display','none');
		
	}
	//发光材质
	function showForGlow(){
		$('#glowPower-tr').css('display','');
		$('#outlineColor-tr').css('display','none');
		$('#outlineWidth-tr').css('display','none');
		$('#gapColor-tr').css('display','none');
		$('#dashLength-tr').css('display','none');
		$('#dashPattern-tr').css('display','none');
		$('#interval-tr').css('display','none');
		
	}
	//od
	function showForOd(){
		$('#interval-tr').css('display','');
		$('#direction-tr').css('display','');
		$('#outlineColor-tr').css('display','none');
		$('#outlineWidth-tr').css('display','none');
		$('#gapColor-tr').css('display','none');
		$('#dashLength-tr').css('display','none');
		$('#dashPattern-tr').css('display','none');
	}
	function hiddenTr(){
		$('#outlineColor-tr').css('display','none');
		$('#outlineWidth-tr').css('display','none');
		$('#glowPower-tr').css('display','none');
		$('#gapColor-tr').css('display','none');
		$('#dashLength-tr').css('display','none');
		$('#dashPattern-tr').css('display','none');
		$('#interval-tr').css('display','none');
		
	}
    
</script>
